import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:second_hand/data/shared_preferences_service.dart';
import 'package:second_hand/pages/profile/change/update_password.dart';
import 'package:second_hand/pages/welcome.dart';

import 'admin_login.dart';
import 'change_avatar.dart';
import 'change_userInfo.dart';

class ChangePage extends StatelessWidget {
  const ChangePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("设置")),
      body: ListView(
        children: <Widget>[
          ListTile(
            title: Text("修改头像"),
            trailing: Icon(Icons.arrow_forward_ios),
            onTap: () {
              Get.to(UpdateAvatarPage());
            },
          ),
          ListTile(
            title: Text("修改个人信息"),
            trailing: Icon(Icons.arrow_forward_ios),
            onTap: () {
              Get.to(() => ChangeUserInfoPage());
            },
          ),
          ListTile(
            title: Text("修改密码"),
            trailing: Icon(Icons.arrow_forward_ios),
            onTap: () {
              Get.to(() => UpdatePasswordPage());
            },
          ),
          ListTile(
            title: Text("退出登录"),
            trailing: Icon(Icons.arrow_forward_ios),
            onTap: () {
              _logout();
            },
          ),
          ListTile(
            title: Text("管理员登录"),
            trailing: Icon(Icons.arrow_forward_ios),
            onTap: () {
              Get.to(()=>AdminLoginPage());
            },
          ),
        ],
      ),
    );
  }
}

void _logout() {
  Get.defaultDialog(
    title: "请确认",
    middleText: '  是否确认退出登录？',
    backgroundColor: Colors.white,
    actions: [
      TextButton(
        onPressed: () {
          Get.back(); // 关闭对话框
        },
        child: const Text('取消'),
      ),
      TextButton(
        onPressed: () async {
            await SharedPreferencesService.clearToken();
            Get.offAll(() => WelcomePage());
            Get.snackbar("退出成功","", duration: const Duration(seconds: 1));
        },
        child: const Text('确认'),
      ),
    ],
  );
}
